package dk.muldbjergskolen.gui;

import java.awt.BorderLayout;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.UIManager;
import javax.swing.JButton;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import dk.muldbjergskolen.ctr.*;
import dk.muldbjergskolen.gui.OpretAnsat.OpretAnsatListener;
import dk.muldbjergskolen.gui.OpretElev.OpretElevListener;
import dk.muldbjergskolen.gui.OpretKlasse.OpretKlasseListener;
import dk.muldbjergskolen.gui.OpretLokale.OpretLokaleListener;
import dk.muldbjergskolen.gui.OpretInventar.OpretInventarListener;
import dk.muldbjergskolen.gui.RetElev.RetElevListener;
import dk.muldbjergskolen.gui.RetFag.RetFagListener;
import dk.muldbjergskolen.gui.RetInventar.RetInventarListener;
import dk.muldbjergskolen.gui.RetKlasse.RetKlasseListener;
import dk.muldbjergskolen.gui.OpretFag.OpretFagListener;
import dk.muldbjergskolen.gui.RetLokale.RetLokaleListener;
import dk.muldbjergskolen.model.Ansat;
import dk.muldbjergskolen.gui.RetAnsat.RetAnsatListener;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

@SuppressWarnings("serial")
public class Main extends JFrame implements OpretKlasseListener, OpretLokaleListener,
		OpretInventarListener, OpretAnsatListener, RetKlasseListener, OpretFagListener,
		RetFagListener, RetInventarListener , RetLokaleListener , RetAnsatListener, OpretElevListener , RetElevListener

{
	private JFrame frame;
	private JTextField textField_AntalAnsat;
	private JTable table_Ansat;
	private JTextField textField_AntalLokaler;
	private JTable table_Lokale;
	private JTextField textField_AntalKlasser;
	private JTable table_klasse;
	private JTextField textField_AntalInventar;
	private JTable table_Inventar;
	private JTextField textField_5;
	private JTextField textField_AntalFag;
	private JTextField textField_AntalElever;
	private JTable table_Elever;
	private JTable table_Fag;

	private KlasseCtr kC = new KlasseCtr();
	private LokaleCtr lC = new LokaleCtr();
	private InventarCtr iC = new InventarCtr();
	private FagCtr fC = new FagCtr();
	private AnsatCtr aC = new AnsatCtr();
	private ElevCtr eC = new ElevCtr();

	private final Ansat brugerlogin;

	/**
	 *  Create the dialog.
	 */
	public Main(Ansat brugerlogin)
	{
		// Sæt nuværende brugerlogin.
		this.brugerlogin = brugerlogin;

		setTitle("Skolesystem");
		setBounds(100, 100, 561, 559);
		getContentPane().setLayout(new BorderLayout());
		{
			JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
			getContentPane().add(tabbedPane, BorderLayout.CENTER);
			{
				JPanel panel_10 = new JPanel();
				tabbedPane.addTab("Skema", null, panel_10, null);
				panel_10.setLayout(new BorderLayout(0, 0));

				JTabbedPane tabbedPane_1_1 = new JTabbedPane(JTabbedPane.TOP);
				panel_10.add(tabbedPane_1_1, BorderLayout.CENTER);

				JPanel panel_1_1 = new JPanel();
				tabbedPane_1_1.addTab("Mit", null, panel_1_1, null);
				panel_1_1.setLayout(null);

				JPanel panel_5_1 = new JPanel();
				panel_5_1.setBounds(10, 39, 515, 344);
				panel_1_1.add(panel_5_1);

				JLabel lblr_1 = new JLabel("År:");
				lblr_1.setBounds(10, 11, 46, 14);
				panel_1_1.add(lblr_1);

				JComboBox<Integer> comboBox_5 = new JComboBox<Integer>();
				comboBox_5.setModel(new DefaultComboBoxModel<Integer>(new Integer[] { 2011, 2012, 2013, 2014 }));
				comboBox_5.setBounds(66, 8, 95, 20);
				panel_1_1.add(comboBox_5);

				JLabel lblUge_1 = new JLabel("Uge:");
				lblUge_1.setBounds(171, 11, 46, 14);
				panel_1_1.add(lblUge_1);

				JComboBox<String> comboBox_1_1 = new JComboBox<String>();
				comboBox_1_1
						.setModel(new DefaultComboBoxModel<String>(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "..." }));
				comboBox_1_1.setBounds(227, 8, 95, 20);
				panel_1_1.add(comboBox_1_1);

				JPanel panel_2_1 = new JPanel();
				tabbedPane_1_1.addTab("Lokale", null, panel_2_1, null);
				panel_2_1.setLayout(null);

				JLabel lblHold = new JLabel("Lokale:");
				lblHold.setBounds(10, 11, 46, 14);
				panel_2_1.add(lblHold);

				JComboBox<String> comboBox_2 = new JComboBox<String>();
				comboBox_2.setModel(new DefaultComboBoxModel<String>(new String[] { "A33", "A34", "A35", "..." }));
				comboBox_2.setBounds(66, 8, 134, 20);
				panel_2_1.add(comboBox_2);

				JPanel panel_3_1 = new JPanel();
				tabbedPane_1_1.addTab("Lærer", null, panel_3_1, null);
				panel_3_1.setLayout(null);

				JLabel lblLrer = new JLabel("Lærer:");
				lblLrer.setBounds(10, 11, 46, 14);
				panel_3_1.add(lblLrer);

				JComboBox<String> comboBox_3 = new JComboBox<String>();
				comboBox_3.setModel(new DefaultComboBoxModel<String>(new String[] { "ABC", "ABD", "ABE", "ABF" }));
				comboBox_3.setBounds(66, 8, 128, 20);
				panel_3_1.add(comboBox_3);

				JPanel panel_4_1 = new JPanel();
				tabbedPane_1_1.addTab("Klasse", null, panel_4_1, null);
				panel_4_1.setLayout(null);

				JLabel lblKlasse = new JLabel("Klasse:");
				lblKlasse.setBounds(10, 11, 46, 14);
				panel_4_1.add(lblKlasse);

				JComboBox<String> comboBox_4 = new JComboBox<String>();
				comboBox_4.setModel(new DefaultComboBoxModel<String>(new String[] { "0a", "0b", "1a", "2a", "3a", "4a", "4b", "5a", "5b" }));
				comboBox_4.setBounds(66, 8, 132, 20);
				panel_4_1.add(comboBox_4);
			}

			JPanel panel_9 = new BookingTab(brugerlogin);
			tabbedPane.addTab("Booking", null, panel_9, null);

			JPanel panel = new JPanel();
			tabbedPane.addTab("Administration", null, panel, null);
			panel.setLayout(new BorderLayout(0, 0));

			JTabbedPane tabbedPane_1 = new JTabbedPane(JTabbedPane.TOP);
			panel.add(tabbedPane_1);

			JPanel panel_1 = new JPanel();
			tabbedPane_1.addTab("Ansatte", null, panel_1, null);
			panel_1.setLayout(null);

			JLabel lblTotalAntalAnsatte = new JLabel("Total antal ansatte:");
			lblTotalAntalAnsatte.setBounds(10, 14, 130, 14);
			panel_1.add(lblTotalAntalAnsatte);

			textField_AntalAnsat = new JTextField();
			textField_AntalAnsat.setEditable(false);
			textField_AntalAnsat.setText("53");
			textField_AntalAnsat.setBounds(150, 11, 86, 20);
			panel_1.add(textField_AntalAnsat);
			textField_AntalAnsat.setColumns(10);

			JButton btnOpretAnsat = new JButton("Opret ansat");
			btnOpretAnsat.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent arg0)
				{
					OpretAnsat oa = new OpretAnsat(Main.this);
					oa.setVisible(true);
				}
			});
			btnOpretAnsat.setBounds(10, 320, 110, 23);
			panel_1.add(btnOpretAnsat);

			JScrollPane scrollPane = new JScrollPane();
			scrollPane.setBounds(10, 50, 495, 259);
			panel_1.add(scrollPane);

			table_Ansat = new JTable();
			table_Ansat.setModel(new DefaultTableModel(
				new Object[][] {
					{null, null, null, null, null, null, null, null, null},
				},
				new String[] {
					"Id", "Fornavn", "Efternavn", "Addresse", "Postnr", "tlf", "Email", "Cpr", "Stilling"
				}
			));
			opdaterAnsatAd();
			scrollPane.setViewportView(table_Ansat);

			JButton btnRetAnsat = new JButton("Ret ansat");
			btnRetAnsat.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					RetAnsat a = new RetAnsat(Main.this);
					a.setVisible(true);
				}
			});
			btnRetAnsat.setBounds(416, 320, 89, 23);
			panel_1.add(btnRetAnsat);

			JPanel panel_2 = new JPanel();
			tabbedPane_1.addTab("Lokaler", null, panel_2, null);
			panel_2.setLayout(null);

			JLabel lblTotalAntalLokaler = new JLabel("Total antal lokaler:");
			lblTotalAntalLokaler.setBounds(10, 14, 130, 14);
			panel_2.add(lblTotalAntalLokaler);

			textField_AntalLokaler = new JTextField();
			textField_AntalLokaler.setText("53");
			textField_AntalLokaler.setEditable(false);
			textField_AntalLokaler.setColumns(10);
			textField_AntalLokaler.setBounds(150, 11, 86, 20);
			panel_2.add(textField_AntalLokaler);

			JScrollPane scrollPane_1 = new JScrollPane();
			scrollPane_1.setBounds(10, 50, 495, 259);
			panel_2.add(scrollPane_1);

			table_Lokale = new JTable();
			table_Lokale.setModel(new DefaultTableModel(
				new Object[][] {
					{null, null, null},
				},
				new String[] {
					"id", "Lokale", "Placering"
				}
			));
			opdaterLokalerAd();
			scrollPane_1.setViewportView(table_Lokale);

			JButton btnOpretLokale = new JButton("Opret lokale");
			btnOpretLokale.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent arg0)
				{
					OpretLokale la = new OpretLokale(Main.this);
					la.setVisible(true);
				}
			});
			btnOpretLokale.setBounds(10, 320, 110, 23);
			panel_2.add(btnOpretLokale);

			JButton btnRetLokale = new JButton("Ret lokale");
			btnRetLokale.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					RetLokale ra = new RetLokale(Main.this);
					ra.setVisible(true);
				}
			});
			btnRetLokale.setBounds(416, 320, 89, 23);
			panel_2.add(btnRetLokale);

			JPanel panel_3 = new JPanel();
			tabbedPane_1.addTab("Klasser", null, panel_3, null);
			panel_3.setLayout(null);

			JLabel lblTotalAntalKlasser = new JLabel("Total antal klasser:");
			lblTotalAntalKlasser.setBounds(10, 14, 130, 14);
			panel_3.add(lblTotalAntalKlasser);

			textField_AntalKlasser = new JTextField();
			textField_AntalKlasser.setEditable(false);
			textField_AntalKlasser.setColumns(10);
			textField_AntalKlasser.setBounds(150, 11, 86, 20);
			panel_3.add(textField_AntalKlasser);

			JScrollPane scrollPane_2 = new JScrollPane();
			scrollPane_2.setBounds(10, 50, 495, 259);
			panel_3.add(scrollPane_2);

			table_klasse = new JTable();
			table_klasse.setModel(new DefaultTableModel(
				new Object[][] {
					{null, null, null},
				},
				new String[] {
					"id", "Klassenavn", "\u00C5rgang"
				}
			));
			scrollPane_2.setViewportView(table_klasse);
			opdaterKlasserAd();

			JButton btnOpretKlasse = new JButton("Opret klasse");

			btnOpretKlasse.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					OpretKlasse k = new OpretKlasse(Main.this);
					k.setVisible(true);

				}
			});
			btnOpretKlasse.setBounds(10, 320, 110, 23);
			panel_3.add(btnOpretKlasse);

			JButton btnRetKlasse = new JButton("Ret Klasse");

			btnRetKlasse.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					RetKlasse k = new RetKlasse(Main.this);
					k.setVisible(true);
				}
			});
			btnRetKlasse.setBounds(416, 320, 89, 23);
			panel_3.add(btnRetKlasse);

			JPanel panel_8 = new JPanel();
			tabbedPane_1.addTab("Elever", null, panel_8, null);
			panel_8.setLayout(null);

			JLabel label_2 = new JLabel("Total antal elever:");
			label_2.setBounds(10, 14, 130, 14);
			panel_8.add(label_2);

			textField_AntalElever = new JTextField();
			textField_AntalElever.setText("536");
			textField_AntalElever.setEditable(false);
			textField_AntalElever.setColumns(10);
			textField_AntalElever.setBounds(150, 11, 86, 20);
			panel_8.add(textField_AntalElever);

			JScrollPane scrollPane_5 = new JScrollPane();
			scrollPane_5.setBounds(10, 50, 495, 259);
			panel_8.add(scrollPane_5);
			
			

			table_Elever = new JTable();
			table_Elever.setModel(new DefaultTableModel(
				new Object[][] {
					{null, null, null, null, null, null, null, null, null},
				},
				new String[] {
					"Id", "Fornavn", "Efternavn", "Adresse", "PostNr", "Telefon", "Email", "Cpr", "Klasse"
				}
			));
			opdaterElevAd();
			scrollPane_5.setViewportView(table_Elever);

			JButton btnOpretElev = new JButton("Opret elev");
			btnOpretElev.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent arg0)
				{
					OpretElev e = new OpretElev(Main.this);
					e.setVisible(true);
				}
			});
			btnOpretElev.setBounds(10, 320, 110, 23);
			panel_8.add(btnOpretElev);

			JButton btnRetElev = new JButton("Ret elev");
			btnRetElev.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					RetElev re = new RetElev(Main.this);
					re.setVisible(true);
				}
			});
			btnRetElev.setBounds(395, 320, 110, 23);
			panel_8.add(btnRetElev);

			JPanel panel_7 = new JPanel();
			tabbedPane_1.addTab("Fag", null, panel_7, null);
			panel_7.setLayout(null);

			JLabel lblTotalAntalFag = new JLabel("Total antal fag:");
			lblTotalAntalFag.setBounds(10, 11, 89, 14);
			panel_7.add(lblTotalAntalFag);

			textField_AntalFag = new JTextField();
			textField_AntalFag.setEditable(false);
			textField_AntalFag.setBounds(109, 8, 86, 20);
			panel_7.add(textField_AntalFag);
			textField_AntalFag.setColumns(10);

			JScrollPane scrollPane_4 = new JScrollPane();
			scrollPane_4.setBounds(10, 50, 495, 259);
			panel_7.add(scrollPane_4);

			table_Fag = new JTable();
			table_Fag.setModel(new DefaultTableModel(
				new Object[][] {
					{null, null, null},
				},
				new String[] {
					"id", "Fag", "Forkortelse"
				}
			));
			scrollPane_4.setViewportView(table_Fag);
			opdaterFagAd();

			JButton btnOpretFag = new JButton("Opret fag");
			btnOpretFag.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					OpretFag of = new OpretFag(Main.this);
					of.setVisible(true);
				}
			});
			btnOpretFag.setBounds(10, 320, 110, 23);
			panel_7.add(btnOpretFag);

			JButton btnRetFag = new JButton("Ret Fag");
			btnRetFag.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					RetFag rf = new RetFag(Main.this);
					rf.setVisible(true);
				}
			});
			btnRetFag.setBounds(395, 320, 110, 23);
			panel_7.add(btnRetFag);

			JPanel panel_4 = new JPanel();
			tabbedPane_1.addTab("Inventar", null, panel_4, null);
			panel_4.setLayout(null);

			JLabel lblTotalAntalTing = new JLabel("Total antal ting:");
			lblTotalAntalTing.setBounds(10, 14, 130, 14);
			panel_4.add(lblTotalAntalTing);

			textField_AntalInventar = new JTextField();
			textField_AntalInventar.setText("23");
			textField_AntalInventar.setEditable(false);
			textField_AntalInventar.setColumns(10);
			textField_AntalInventar.setBounds(150, 11, 86, 20);
			panel_4.add(textField_AntalInventar);

			JScrollPane scrollPane_3 = new JScrollPane();
			scrollPane_3.setBounds(10, 50, 495, 259);
			panel_4.add(scrollPane_3);

			table_Inventar = new JTable();
			table_Inventar.setModel(new DefaultTableModel(
				new Object[][] {
					{null, null, null, null},
				},
				new String[] {
					"id", "Navn", "Beskrivelse", "Antal"
				}
			));
			opdaterInventarAd();
			scrollPane_3.setViewportView(table_Inventar);

			JButton btnOpretTing = new JButton("Opret inventar");
			btnOpretTing.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent arg0)
				{
					OpretInventar it = new OpretInventar(Main.this);
					it.setVisible(true);
				}
			});
			btnOpretTing.setBounds(10, 320, 110, 23);
			panel_4.add(btnOpretTing);

			JButton btnRetTing = new JButton("Ret inventar");
			btnRetTing.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					RetInventar ri = new RetInventar(Main.this);
					ri.setVisible(true);
				}
			});
			btnRetTing.setBounds(395, 320, 110, 23);
			panel_4.add(btnRetTing);

			JPanel panel_5 = new JPanel();
			tabbedPane_1.addTab("Skemaplanlægning", null, panel_5, null);
			panel_5.setLayout(null);

			JLabel label = new JLabel("Klassetrin:");
			label.setBounds(10, 39, 58, 14);
			panel_5.add(label);

			JComboBox<String> comboBox = new JComboBox<String>();
			comboBox.setBounds(101, 36, 88, 20);
			panel_5.add(comboBox);

			textField_5 = new JTextField();
			textField_5.setEditable(false);
			textField_5.setText("3");
			textField_5.setColumns(10);
			textField_5.setBounds(100, 61, 25, 20);
			panel_5.add(textField_5);

			JLabel label_1 = new JLabel("Antal klasser :");
			label_1.setBounds(10, 64, 74, 14);
			panel_5.add(label_1);

			JButton button = new JButton("Generer skema!");
			button.setBounds(10, 92, 152, 23);
			panel_5.add(button);

			JPanel panel_6 = new JPanel();
			panel_6.setBounds(10, 128, 497, 252);
			panel_5.add(panel_6);

			JLabel lblrgang = new JLabel("Årgang:");
			lblrgang.setBounds(10, 11, 46, 14);
			panel_5.add(lblrgang);

			JComboBox<String> comboBox_1 = new JComboBox<String>();
			comboBox_1.setModel(new DefaultComboBoxModel<String>(new String[] { "2013", "2014", "2015", "2016" }));
			comboBox_1.setBounds(101, 8, 101, 20);
			panel_5.add(comboBox_1);
		}
	}

	// Opdaterer listen af klasser i adminstration
	public void opdaterKlasserAd()
	{
		try
		{
			ArrayList<dk.muldbjergskolen.model.Klasse> a = kC.findKlasser();
			removeRowKlasse();
			for (dk.muldbjergskolen.model.Klasse kla : a)
			{
				((DefaultTableModel) table_klasse.getModel()).addRow(new Object[] { kla.getId(), kla.getKlasseNavn(), kla.getAargang() });
			}
			String taellerKlasse = Integer.toString(table_klasse.getRowCount());
			textField_AntalKlasser.setText(taellerKlasse);
		}

		catch (Exception e)
		{
			JOptionPane.showMessageDialog(frame, "Ingen klasser blev fundet.");
		}
	}

	// fjerner alle klasser fra jtabel i administration
	private void removeRowKlasse()
	{
		DefaultTableModel model = (DefaultTableModel) table_klasse.getModel();

		while (model.getRowCount() >= 1)
		{
			model.removeRow(0);
		}
	}

	/***
	 * Metoden til interfacet Opret KlasseListener.
	 */
	@Override
	public void OnNewKlasse()
	{
		opdaterKlasserAd();
	}

	/***
	 * Metoden til interfacet ret KlasseListener.
	 */
	@Override
	public void OnRettetKlasse()
	{
		opdaterKlasserAd();
	}

	// Opdaterer listen af Lokaler i adminstration
	public void opdaterLokalerAd()
	{
		try
		{
			ArrayList<dk.muldbjergskolen.model.Lokale> b = lC.findLokaler();
			removeRowLokaler();
			for (dk.muldbjergskolen.model.Lokale ila : b)
			{
				((DefaultTableModel) table_Lokale.getModel()).addRow(new Object[] { ila.getId(), ila.getNavn(), ila.getPlacering() });
			}
			String taellerLokaler = Integer.toString(table_Lokale.getRowCount());
			textField_AntalLokaler.setText(taellerLokaler);
		}

		catch (Exception e)
		{
			JOptionPane.showMessageDialog(frame, "Ingen Lokaler blev fundet.");
		}
	}

	// fjerner lokaler fra table i administration
	private void removeRowLokaler()
	{
		DefaultTableModel model = (DefaultTableModel) table_Lokale.getModel();

		while (model.getRowCount() >= 1)
		{
			model.removeRow(0);
		}
	}

	/***
	 * Metoden til interfacet OpretLokaleListener.
	 */
	@Override
	public void OnNewLokale()
	{
		opdaterLokalerAd();
	}

	// Opdaterer listen af Inventar i adminstration
	public void opdaterInventarAd()
	{
		try
		{
			ArrayList<dk.muldbjergskolen.model.Inventar> i = iC.findInventar();
			removeRowInventar();
			for (dk.muldbjergskolen.model.Inventar ila : i)
			{
				((DefaultTableModel) table_Inventar.getModel()).addRow(new Object[] { ila.getId(), ila.getNavn(), ila.getBeskrivelse(), ila.getAntal() });
			}
			String taellerInventar = Integer.toString(table_Inventar.getRowCount());
			textField_AntalInventar.setText(taellerInventar);
		}

		catch (Exception e)
		{
			JOptionPane.showMessageDialog(frame, "Ingen Inventar blev fundet.");
		}
	}

	public void opdaterFagAd()
	{
		try
		{
			ArrayList<dk.muldbjergskolen.model.Fag> i = fC.findFagene();
			removeRowFag();
			for (dk.muldbjergskolen.model.Fag fla : i)
			{
				((DefaultTableModel) table_Fag.getModel()).addRow(new Object[] { fla.getId(), fla.getNavn(), fla.getForkortelse() });
			}
			String taellerFag = Integer.toString(table_Fag.getRowCount());
			textField_AntalFag.setText(taellerFag);
		}

		catch (Exception e)
		{
			JOptionPane.showMessageDialog(frame, "Ingen fag blev fundet");
		}
	}
	
	public void opdaterElevAd()
	{
		try
		{
			ArrayList<dk.muldbjergskolen.model.Elev> e = eC.findElever();
			removeRowElev();
			for (dk.muldbjergskolen.model.Elev ela : e)
			{
				((DefaultTableModel) table_Elever.getModel()).addRow(new Object[] { ela.getId() , ela.getFornavn(), ela.getEfternavn(), ela.getAddresse(), ela.getPostNr(), ela.getTlf(), ela.getEmail(), ela.getCpr(), ela.getKlasse().getKlasseNavn() });
			}
			String taellerElever = Integer.toString(table_Elever.getRowCount());
			textField_AntalElever.setText(taellerElever);
		}
		
		catch (Exception e)
		{
			JOptionPane.showMessageDialog(frame, "Ingen Elever blev fundet");
		}
	}
	
	
	
	 // fjerner Elev fra table i administration
	private void removeRowElev()
	{
		DefaultTableModel model = (DefaultTableModel) table_Elever.getModel();
		while (model.getRowCount() >= 1)
		{
			model.removeRow(0);
		}
	}
	
	public void opdaterAnsatAd()
	{
		try
		{
			ArrayList<dk.muldbjergskolen.model.Ansat> a = aC.findAnsatte();
			removeRowAnsat();
			for (dk.muldbjergskolen.model.Ansat ala : a)
			{
				((DefaultTableModel) table_Ansat.getModel()).addRow(new Object[] { ala.getId(), ala.getFornavn(), ala.getEfternavn(), ala.getAddresse(), ala.getPostNr(), ala.getTlf(), ala.getEmail(), ala.getCpr(), ala.getStilling() });
			}
			String taellerAnsat = Integer.toString(table_Ansat.getRowCount());
			textField_AntalAnsat.setText(taellerAnsat);
		}

		catch (Exception e)
		{
			JOptionPane.showMessageDialog(frame, "Ingen Ansat blev fundet");
		}
	}
	
	// fjerner Ansat fra table i administration
	private void removeRowAnsat()
	{
		DefaultTableModel model = (DefaultTableModel) table_Ansat.getModel();

		while (model.getRowCount() >= 1)
		{
			model.removeRow(0);
		}
	}

	// fjerner fag fra table i administration
	private void removeRowFag()
	{
		DefaultTableModel model = (DefaultTableModel) table_Fag.getModel();

		while (model.getRowCount() >= 1)
		{
			model.removeRow(0);
		}
	}

	// fjerner Inventar fra table i administration
	private void removeRowInventar()
	{
		DefaultTableModel model = (DefaultTableModel) table_Inventar.getModel();

		while (model.getRowCount() >= 1)
		{
			model.removeRow(0);
		}
	}

	/***
	 * Metoden til interfacet opretInventarListener.
	 */
	@Override
	public void OnNewInventar()
	{
		opdaterInventarAd();
	}

	/***
	 * Metoden til interfacet opretFagListener.
	 */
	@Override
	public void OnNewFag()
	{
		opdaterFagAd();
	}
	
	/***
	 * Metoden til interfacet RettetFagListener.
	 */
	@Override
	public void OnRettetFag()
	{
		opdaterFagAd();
	}
	
	/***
	 * Metoden til interfacet RettetInventarListener.
	 */
	@Override
	public void OnRettetInventar()
	{
		opdaterInventarAd();
	}

	/***
	 * Metoden til interfacet RettetLokalerListener.
	 */
	@Override
	public void OnRettetLokale()
	{
		opdaterLokalerAd();
	}
	
	/***
	 * Metoden til interfacet OpretAnsatListener.
	 */
	@Override
	public void OnNewAnsat() 
	{
		opdaterAnsatAd();	
	}

	/***
	 * Metoden til interfacet rettetAnsatListener.
	 */
	@Override
	public void OnRettetAnsat() {
		opdaterAnsatAd();	
	}

	/***
	 * Metoden til interfacet opretElevListener.
	 */
	@Override
	public void OnNewElev()
	{
		opdaterElevAd();
	}
	
	/***
	 * Metoden til interfacet rettetElevListener.
	 */
	@Override
	public void OnRettetElev() {
		opdaterElevAd();
	}
}
